package com.ufaud.ais.sys.view;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.springframework.security.GrantedAuthority;
import org.springframework.security.GrantedAuthorityImpl;
import org.springframework.security.userdetails.UserDetails;

import com.ufaud.ais.sys.entity.Department;
import com.ufaud.ais.sys.entity.Employee;
import com.ufaud.ais.sys.entity.Role;
import com.ufaud.ais.sys.entity.TransferRecord;

/**
 * 
 * @author Chenjd 2010-6-24
 * 
 */
public class EmployeeView implements UserDetails {
	private static final long serialVersionUID = 5613702903380767889L;

	private Employee employee;
	private Department department;
	private Set<Role> roleSet = new HashSet<Role>();
	private Set<TransferRecord> transferRecordSet = new HashSet<TransferRecord>();

	public EmployeeView(Employee employee) {
		this.employee = employee;
	}

	public String getAccountName() {
		return employee.getAccountName();
	}

	public String getAccountPassword() {
		return employee.getAccountPassword();
	}

	public GrantedAuthority[] getAuthorities() {
		List<GrantedAuthority> resultList = new ArrayList<GrantedAuthority>();
		for (Iterator<Role> iter = roleSet.iterator(); iter.hasNext();) {
			Role role = iter.next();
			GrantedAuthorityImpl ga = new GrantedAuthorityImpl(role
					.getRoleCode());
			resultList.add(ga);
		}
		return resultList.toArray(new GrantedAuthority[resultList.size()]);
	}

	public String getEmail() {
		return employee.getEmail();
	}

	public Date getEmployDate() {
		return employee.getEmployDate();
	}

	public String getEmployeeCode() {
		return employee.getEmployeeCode();
	}

	public Long getEmployeeId() {
		return employee.getEmployeeId();
	}

	public String getEmployeeName() {
		return employee.getEmployeeName();
	}

	public String getJob() {
		return employee.getJob();
	}

	public String getPassword() {
		return employee.getAccountPassword();
	}

	public Set<Role> getRoleSet() {
		return roleSet;
	}

	public Department getDepartment() {
		return department;
	}

	public String getUsername() {
		return employee.getAccountName();
	}

	public boolean isAccountExpired() {
		return employee.isAccountExpired();
	}

	public boolean isAccountLocked() {
		return employee.isAccountLocked();
	}

	public boolean isAccountNonExpired() {
		return !isAccountExpired();
	}

	public boolean isAccountNonLocked() {
		return !isAccountLocked();
	}

	public boolean isCredentialsExpired() {
		return employee.isCredentialsExpired();
	}

	public boolean isCredentialsNonExpired() {
		return !isCredentialsExpired();
	}

	public boolean isEnabled() {
		return employee.isEnabled();
	}

	public String toString() {
		return employee.toString();
	}

	public void setDepartment(Department department) {
		this.department = department;
	}

	public void setRoleSet(Set<Role> roleSet) {
		this.roleSet = roleSet;
	}

	public Set<TransferRecord> getTransferRecordSet() {
		return transferRecordSet;
	}

	public void setTransferRecordSet(Set<TransferRecord> transferRecordSet) {
		this.transferRecordSet = transferRecordSet;
	}

}
